<?php

include 'lib.php';

$artists = Database::query("SELECT * FROM `tracks`");

foreach ($artists as $artist)
{
    $artist['artist'] = mysql_real_escape_string($artist['artist']);
    $exists = Database::query("SELECT * FROM artists WHERE name LIKE '$artist[artist]'");
    
    if (!$exists[0]['id'])
    {
        $id = Database::insert("INSERT INTO `artists` (`name`) VALUES ('$artist[artist]')");
    }
    else $id = $exists[0]['id'];

    Database::insert("UPDATE `tracks` SET `artist_id` = $id WHERE `id` = ".$artist['id']);
}

?>